package com.mars.component.scheduler.exception;

import com.mars.common.exception.BizException;
import com.mars.common.utils.ExceptionUtil;

public class SchedulerJobException extends BizException {

	private static final long serialVersionUID = 1L;

	/**
	 * 获取定时任务CronTrigger出现异常
	 */
	public static final SchedulerJobException CRON_TRIGGER_EXCEPTION = new SchedulerJobException(10020114, " 获取定时任务CronTrigger出现异常");
	
	/**
	 * 创建定时任务失败
	 */
	public static final SchedulerJobException CREATE_SCHEDULER_FAILED = new SchedulerJobException(10020114, " 创建定时任务失败");
	
	/**
	 * 执行定时任务失败
	 */
	public static final SchedulerJobException RUN_SCHEDULER_FAILED = new SchedulerJobException(10020114, " 执行定时任务失败");
	
	/**
	 * 立即执行定时任务失败
	 */
	public static final SchedulerJobException RUN_NOW = new SchedulerJobException(10020114, " 立即执行定时任务失败");
	
	/**
	 * 删除定时任务失败
	 */
	public static final SchedulerJobException DELETE_JOB_EXCEPTION = new SchedulerJobException(10020114, " 删除定时任务失败");
	
	/**
	 * 立即执行定时任务失败
	 */
	public static final SchedulerJobException RESUME_EXCEPTION = new SchedulerJobException(10020114, " 恢复定时任务调度失败");
	
	/**
	 * 暂停定时任务失败
	 */
	public static final SchedulerJobException PAUSE_JOB_EXCEPTION = new SchedulerJobException(10020114, " 暂停定时任务失败");
	
	/**
	 * 修改任务调度的触发时间
	 */
	public static final SchedulerJobException RESCHEDULER_JOB_EXCEPTION = new SchedulerJobException(10020114, " 修改任务调度的触发时间");
	
	public SchedulerJobException() {
	}
	
	public SchedulerJobException(String msg, Throwable e) {
		super(msg, e);
		this.msg = msg;
	}

	public SchedulerJobException(int code, String msg) {
		super(code, msg);
	}
	
	public SchedulerJobException(String msgFormat, Object... args) {
		super(msgFormat, args);
	}
	
	public SchedulerJobException(int code, String msgFormat, Object... args) {
		super(code, msgFormat, args);
	}
	
	
	public SchedulerJobException newInstance(String msgFormat, Object... args) {
		return new SchedulerJobException(this.code, msgFormat, args);
	}
	
	public SchedulerJobException logError(Exception e) {
		StringBuffer sb = new StringBuffer() ;
		for(int i=0; i<20; i++){sb.append("=========");}
		logger.error(
				"\r\n"+sb.toString()+"\r\n"+
						"====>SchedulerJobException, code:" + this.code + ", msg:" + this.msg + "  \r\n{} {}", 
						ExceptionUtil.getStackTrace(e), 
						"\r\n"+sb.toString()+"\r\n"
				);
		return new SchedulerJobException(this.code, this.msg);
	}
	
}
